package srcTA;

import java.io.File;
import java.io.IOException;

import lib.ArgumentValidator;
import lib.logging.ANSIConsoleLogger;
import lib.logging.ILogger;

public class TowerAllocator
{
    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException
    {
        ILogger logger = new ANSIConsoleLogger();

        if (args.length != 2)
        {
            logger.LogError(
                    "Incorrect number of paramets: %d. Usage: java TowerAllocator <input file> <output file>",
                    args.length);

            System.exit(1);
        }

        String inputFileName = args[0];
        String outputFileName = args[1];
        
        TowerAllocator towerAllocator = new TowerAllocator(logger, logger, inputFileName);

        StateManager stateManager = new StateManager(
                towerAllocator.inputData.Bids());
        ImprovedHillClimbing hcRR = new ImprovedHillClimbing(stateManager, logger, new File(outputFileName));
        
        // AcceptedBids acceptedBids = hcRR.GetSolutionWithRandomInitialState();
        AcceptedBids acceptedBidsGreedy = hcRR.GetSolutionWithGreedyInitialState(towerAllocator.inputData.TimeThreshold() * 60 * 1000);
        stateManager.PrintAcceptedBidsWithDetails(acceptedBidsGreedy, logger);
        
    }

    private InputData inputData;

    public TowerAllocator(ILogger logger, ILogger consoleLogger, String inputFile) throws IOException
    {
        ArgumentValidator.IsNotNull("logger", logger);
        ArgumentValidator.IsNotNull("consoleLogger", consoleLogger);
        ArgumentValidator.IsNotNullOrEmpty("inputFile", inputFile);

        this.inputData = InputData.ReadDataFromFile(new File(inputFile));
    }
}
